home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: How to get a random string each time??
- Date: 14 Feb 1996 15:39:01 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Feb14083901@qcd.lanl.gov>
- References: <4fh5od$qq0@news.nevada.edu> <4fsi8o$4kl@prairie.nodak.edu>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: wstark@prairie.nodak.edu's message of 14 Feb 1996 05:49:44 -0600
-
- In article <4fsi8o$4kl@prairie.nodak.edu> wstark@prairie.nodak.edu
- (Just Me) writes:
- <snip>
- > j = rand();
-
- > while(j>=10)
- > j=j/10;
-
- I do not understand WHY someone would right code like this. There are many
-
- I will endeavour to give you one possible reason...
-
- other methods of reducing the range of random numbers without resorting to
- a division in a loop (most inefficient). Here is the most obvious:
-
- j %= 10;
-
- (if you don't understand that, you really need to read a good book on C).
-
- Probably because for one reason or the other, the upper bits of the
- random number generated were more random than the lower bits.
-
- If you do not understand how that _could_ be, you need to read a good
- book on random numbers :-)
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-